package j2024.j202409;

public class j0907 {
    /**
     * 674. 最长连续递增序列
     * @param nums
     * @return
     */
    public int findLengthOfLCIS(int[] nums) {
        int ret = 1;
        for (int i = 0; i < nums.length;) {
            int j = i+1;
            while(j<nums.length && nums[j]>nums[j-1]){
                j++;
            }
            ret = Math.max(ret,j-i);
            i = j;
        }
        return ret;
    }

    /**
     * 121. 买卖股票的最佳时机
     * @param prices
     * @return
     */
    public int maxProfit1(int[] prices) {
        int minVal = Integer.MAX_VALUE;
        int ret = 0;
        for (int i = 0; i < prices.length; i++) {
            minVal = Math.min(minVal,prices[i]);
            ret = Math.max(prices[i]-minVal,ret);
        }
        return ret;
    }

    /**
     * 122. 买卖股票的最佳时机 II
     * @param prices
     * @return
     */
    public int maxProfit2(int[] prices) {
        int ret = 0;
        for (int i = 0; i < prices.length;i++) {
            int j = i;
            while(j+1<prices.length && prices[j]<prices[j+1]){
                j++;
            }
            ret+=(prices[j]-prices[i]);
            i = j;
        }
        return ret;
    }
    public int maxProfit(int[] prices) {
        int ret = 0;
        for (int i = 0; i < prices.length; i++) {
            if(i+1<prices.length && prices[i]<prices[i+1]){
                ret+=(prices[i+1]-prices[i]);
            }
        }
        return ret;
    }
}
